package jjn.acwing.algorithm_basic.chapter1.pre_sum;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023-09-20 08:40
 */
public class Acwing795 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), m = scanner.nextInt();
        int[] nums = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            nums[i] = scanner.nextInt();
        }
        int[] preSum = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            preSum[i] = preSum[i - 1] + nums[i];
        }
        while (m-- > 0) {
            int l = scanner.nextInt();
            int r = scanner.nextInt();
            int res = preSum[r] - preSum[l - 1];
            System.out.println(res);
        }
    }
}
